package com.example.config;

import com.example.handle.MyLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
 * 自定义拦截器的配置类
 */
@Configuration
public class MyConfig implements WebMvcConfigurer {
    @Autowired
    private MyLoginInterceptor myLoginInterceptor;
    //用于专门注册自定义拦截器的方法
    @Override
    public void addInterceptors(InterceptorRegistry registry) {//InterceptorRegistry 注册对象
        registry.addInterceptor(myLoginInterceptor)
                .addPathPatterns("/**")//拦截所有请求
                .excludePathPatterns("/login");//排除登录接口
    }
}
